package com.clarte.feeInfo.service;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.clarte.common.action.PagerList;
import com.clarte.common.dao.BaseDao;
import com.clarte.model.FeeInfo;
@Service("feeInfoService")
@Transactional
public class FeeInfoServiceImpl implements FeeInfoService {
	@Resource(name="baseDao")
	private BaseDao<FeeInfo, Integer> baseDao;
	
	@Override
	public void addFeeInfo(FeeInfo feeInfo) {
		baseDao.save(feeInfo);
	}

	@Override
	public void delFeeInfo(Integer... id) {
		baseDao.delete(id);
	}

	@Override
	public void editFeeInfo(FeeInfo feeInfo) {
		baseDao.update(feeInfo);
	}

	@Override
	public List<FeeInfo> findFeeInfo(String startDate,String endDate, int pageNo, int rows) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FeeInfo.class);
		if(startDate!=null && !startDate.trim().equals("")){
			criteria.add(Restrictions.ge("date", startDate));
		}
		if(endDate != null && !endDate.trim().equals("")){
			criteria.add(Restrictions.le("date", endDate));
		}
		List list = baseDao.findByCriteria(criteria, (pageNo-1)*rows, rows);
		int records = Long.valueOf(baseDao.getTotal(criteria.setProjection(Projections.rowCount()))).intValue();
		return PagerList.getResult(list, records);
	}

}
